package org.wutopia.labcloud.domain.product.controller;

import jakarta.annotation.Nonnull;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.wutopia.labcloud.domain.product.controller.vo.input.ProductCreateAdInputVO;
import org.wutopia.labcloud.domain.product.controller.vo.output.ProductGetAdvertisingOutputVO;
import org.wutopia.labcloud.domain.product.service.ProductAdvertisingService;
import org.wutopia.labcloud.library.common.base.CodedMessage;
import org.wutopia.labcloud.library.common.base.CommonResponse;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/product/advertising")
public class ProductAdvertisingController {

    private ProductAdvertisingService productAdvertisingService;

    @GetMapping("/list")
    public ResponseEntity<CodedMessage<List<ProductGetAdvertisingOutputVO>>> getAdvertisingList() throws Exception {

        List<ProductGetAdvertisingOutputVO> advertising = productAdvertisingService.getAdvertising();

        return CommonResponse.successWithData(advertising);
    }

    @PostMapping("/create")
    public ResponseEntity<CodedMessage<String>> createAd(@RequestBody ProductCreateAdInputVO vo) {

        productAdvertisingService.createAd(vo);

        return CommonResponse.success();
    }

    @GetMapping("/delete/{id}")
    public ResponseEntity<CodedMessage<String>> delete(@PathVariable @Validated @Nonnull Long id) {

        productAdvertisingService.deleteAd(id);
        return CommonResponse.success();
    }
}
